package com.hongxun.project.assets.pPicture.service;

import java.util.List;
import java.util.UUID;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.hongxun.project.assets.pPicture.mapper.PPictureMapper;
import com.hongxun.project.assets.pPicture.domain.PPicture;
import com.hongxun.project.assets.pPicture.service.IPPictureService;
import com.hongxun.common.utils.text.Convert;

/**
 * 现场照片 服务层实现
 *
 * @author hongxun
 * @date 2019-03-19
 */
@Service
public class PPictureServiceImpl implements IPPictureService {
    @Autowired
    private PPictureMapper pPictureMapper;

    /**
     * 查询现场照片信息
     *
     * @param id 现场照片ID
     * @return 现场照片信息
     */
    @Override
    public PPicture selectPPictureById(String id, String taskId) {
        return pPictureMapper.selectPPictureById(id, taskId);
    }

    @Override
    public PPicture selectPPictureByIdForState(String id, String taskId) {
        return pPictureMapper.selectPPictureByIdForState(id, taskId);
    }

    /**
     * 查询现场照片列表
     *
     * @param pPicture 现场照片信息
     * @return 现场照片集合
     */
    @Override
    public List<PPicture> selectPPictureList(PPicture pPicture) {
        return pPictureMapper.selectPPictureList(pPicture);
    }

    @Override
    public List<PPicture> selectListOrderByType(PPicture pPicture) {
        return pPictureMapper.selectListOrderByType(pPicture);
    }

    /**
     * 新增现场照片
     *
     * @param pPicture 现场照片信息
     * @return 结果
     */
    @Override
    public int insertPPicture(PPicture pPicture) {
        pPicture.setId(UUID.randomUUID().toString());
        return pPictureMapper.insertPPicture(pPicture);
    }

    /**
     * 修改现场照片
     *
     * @param pPicture 现场照片信息
     * @return 结果
     */
    @Override
    public int updatePPicture(PPicture pPicture) {
        return pPictureMapper.updatePPicture(pPicture);
    }

    /**
     * 删除现场照片对象
     *
     * @param ids 需要删除的数据ID
     * @return 结果
     */
    @Override
    public int deletePPictureByIds(String ids) {
        return pPictureMapper.deletePPictureByIds(Convert.toStrArray(ids));
    }


    @Override
    public int deletePPictureByIdsAndTaskIds(String ids, String taskIds) {
        return pPictureMapper.deletePPictureByIdsAndTaskIds(Convert.toStrArray(ids), Convert.toStrArray(taskIds));
    }

    @Override
    public void insertOrReplaceOrDelete(List<PPicture> entities) {
        for (PPicture d : entities) {
//			if (d.getDatastate().equals("删除")) {
//				pPictureMapper.deletePPictureByIdsAndTaskIds(Convert.toStrArray(d.getId()) , Convert.toStrArray(d.getTaskId()));
//			} else {
            PPicture pPicture = pPictureMapper.selectPPictureById(d.getId(), d.getTaskId());
            if (pPicture == null) {
                pPictureMapper.insertPPicture(d);
            } else {
                pPictureMapper.updatePPicture(d);
            }
//			}
        }
    }

}
